﻿using ctolua.Models.Enum;

namespace ctolua.Models.UI.control
{
    public class MCSkillBtn : Mui
    {
        public override EUi type { get => EUi.技能按钮; set => base.type = EUi.技能按钮; }


        private Ability _skill;
        /// <summary>
        /// 绑定技能对象到控件 null 解绑
        /// </summary>
        public Ability skill
        {
            get => _skill;
            set
            {
                if (value == null)
                {
                    if (this._skill!=null)
                    {
                        game_api.unbind_skill_on_ui_comp(this.role, this._skill, this.id);
                    }
                    
                }
                else
                {
                    game_api.set_skill_on_ui_comp(this.role, value, this.id);
                }

                _skill = value;
            }
        }

        private EKeyboardKey? _key;
        /// <summary>
        /// 设置按钮快捷键
        /// </summary>
        public EKeyboardKey? key
        {
            get => _key;
            set
            {
                if (value != null)
                {
                    game_api.set_btn_short_cut(this.role, this.id, (int)value);
                }

                _key = value;
            }
        }

        private int? _key2;
        /// <summary>
        /// 设置按钮快捷键 
        /// </summary>
        public int? key2
        {
            get => _key2;
            set
            {
                if (value != null)
                {
                    game_api.set_btn_short_cut(this.role, this.id, value);
                }

                _key2 = value;
            }
        }

        private EKeyboardKey? _smart_cast_key;
        /// <summary>
        /// 设置智能施法快捷键
        /// </summary>
        public EKeyboardKey? smart_cast_key
        {
            get => _smart_cast_key;
            set
            {
                if (value != null)
                {
                    game_api.set_skill_btn_smart_cast_key(this.role, this.id, (int)value);
                }

                _smart_cast_key = value;
            }
        }


        private EKeyboardKey? _meta_key;
        /// <summary>
        /// 设置智能施法组合快捷键
        /// </summary>
        public EKeyboardKey? meta_key
        {
            get => _meta_key;
            set
            {
                if (value != null)
                {
                    game_api.set_skill_btn_func_smart_cast_key(this.role, this.id, (int)value);
                }

                _meta_key = value;
            }
        }

        public MCSkillBtn(){}

        public MCSkillBtn(string id) : base(id)
        {
            getChild();
        }

        public MCSkillBtn(MCSkillBtn u) : base(u)
        {
            getChild();
            this.key = u.key;
            this.key2 = u.key2;
        }
        public MCLabel 技能等级 { get; set; }
        public MCImage 技能框 { get; set; }
        public MCLabel 技能cd { get; set; }
        public MCImage 技能图标 { get; set; }
        public MCButton 升级按钮 { get; set; }
        public MCLabel 技能层数 { get; set; }
        public MCImage 技能消耗不足 { get; set; }
        public MCImage 技能禁用 { get; set; }
        public MCLabel 冷却显示 { get; set; }
        public MCLabel 快捷键 { get; set; }

        /// <summary>
        /// 获得子控件
        /// </summary>
        public void getChild()
        {
            this.技能等级 = this.get_comp_by_path<MCLabel>("skill_level_label");
            this.技能等级.show = false;

            this.技能框 = this.get_comp_by_path<MCImage>("skill_frame_img");
            this.技能框.relative0();

            this.技能cd = this.get_comp_by_path<MCLabel>("skill_cd_progress");
            this.技能cd.relative0();

            this.技能图标 = this.get_comp_by_path<MCImage>("skill_icon_img");
            this.技能图标.relative0();

            this.升级按钮 = this.get_comp_by_path<MCButton>("skill_upgrade_btn");
            this.升级按钮.relative0();
            this.升级按钮.image_id = 100350;

            this.技能层数 = this.get_comp_by_path<MCLabel>("skill_stack_label");
            this.技能层数.adaptation(EUiAdaptOption.右侧,5);
            this.技能层数.adaptation(EUiAdaptOption.底部, 5);

            this.技能消耗不足 = this.get_comp_by_path<MCImage>("skill_consume_mask_img");
            this.技能消耗不足.relative0();

            this.技能禁用 = this.get_comp_by_path<MCImage>("skill_disable_img");
            this.技能禁用.relative0();

            this.冷却显示 = this.get_comp_by_path<MCLabel>("skill_cd_label");
            this.冷却显示.relative0();
            this.冷却显示.size = 40;

            this.快捷键 = this.get_comp_by_path<MCLabel>("skill_shortcut_label");
            this.快捷键.adaptation(EUiAdaptOption.左侧, 5);
            this.快捷键.adaptation(EUiAdaptOption.底部, 5);

        }
    }
}
